package me.zhengjie.modules.system.rest;

import me.zhengjie.annotation.Log;
import lombok.RequiredArgsConstructor;
import java.util.List;

import me.zhengjie.base.LazyData;
import me.zhengjie.modules.system.domain.PetBreeds;
import me.zhengjie.modules.system.domain.vo.PetBreedsQueryCriteria;
import me.zhengjie.modules.system.service.PetBreedsService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.utils.PageResult;

/**
* @author ck
* @date 2025-02-10
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "宠物品种管理管理")
@RequestMapping("/api/petBreeds")
public class PetBreedsController {

    private final PetBreedsService petBreedsService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('petBreeds:list')")
    public void exportPetBreeds(HttpServletResponse response, PetBreedsQueryCriteria criteria) throws IOException {
        petBreedsService.download(petBreedsService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询宠物品种管理")
    @ApiOperation("查询宠物品种管理")
    @PreAuthorize("@el.check('petBreeds:list')")
    public ResponseEntity<LazyData<PetBreeds>> queryPetBreeds(PetBreedsQueryCriteria criteria, Page<Object> page){
        return new ResponseEntity<>(petBreedsService.queryAll(criteria,page),HttpStatus.OK);
    }

    @GetMapping("category/{id}")
    @Log("查询类别下的宠物品种")
    @ApiOperation("查询宠物品种")
    @PreAuthorize("@el.check('petBreeds:list')")
    public ResponseEntity<LazyData<PetBreeds>> queryPetBreedsByCategoryId(PetBreedsQueryCriteria criteria, Page<Object> page, @PathVariable Integer id){
        criteria.setCategoryId(id);
        return new ResponseEntity<>(petBreedsService.queryAll(criteria,page),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增宠物品种管理")
    @ApiOperation("新增宠物品种管理")
    @PreAuthorize("@el.check('petBreeds:add')")
    public ResponseEntity<Object> createPetBreeds(@Validated @RequestBody PetBreeds resources){
        petBreedsService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改宠物品种管理")
    @ApiOperation("修改宠物品种管理")
    @PreAuthorize("@el.check('petBreeds:edit')")
    public ResponseEntity<Object> updatePetBreeds(@Validated @RequestBody PetBreeds resources){
        petBreedsService.update(resources);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @DeleteMapping
    @Log("删除宠物品种管理")
    @ApiOperation("删除宠物品种管理")
    @PreAuthorize("@el.check('petBreeds:del')")
    public ResponseEntity<Object> deletePetBreeds(@RequestBody List<Integer> ids) {
        petBreedsService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}